<style type="text/css">
    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="物资项名称" prop="title">
            <i-input v-model="formValidate.title" placeholder="请输入物资项名称"></i-input>
        </Form-item>
        <Form-item label="型号" prop="serial">
            <i-input v-model="formValidate.serial" placeholder="请输入型号"></i-input>
        </Form-item>
        <Form-item label="规格" prop="size">
            <i-input v-model="formValidate.size" placeholder="请输入规格"></i-input>
        </Form-item>
        <Form-item label="厂商" prop="vender">
            <i-input v-model="formValidate.vender" placeholder="请输入厂商"></i-input>
        </Form-item>
        <Form-item label="采购源" prop="byfrom">
            <i-input v-model="formValidate.byfrom" placeholder="请输入采购源"></i-input>
        </Form-item>
        <Form-item label="采购源联系人" prop="fromcontact">
            <i-input v-model="formValidate.fromcontact" placeholder="请输入采购源联系人"></i-input>
        </Form-item>
        <Form-item label="采购源联系电话" prop="fromphone">
            <i-input v-model="formValidate.fromphone" placeholder="请输入采购源联系电话"></i-input>
        </Form-item>
        <Form-item label="分配的物资分类" prop="fortype">
            <i-select v-model="formValidate.fortype" placeholder="请选择分配的物资分类">
                <template v-for="(item,index) in fortypeArr">
                    <i-option :value="item.Value">{{item.Value}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    title: '',
                    serial: '',
                    size: '',
                    vender: '',
                    byfrom: '',
                    fromcontact: '',
                    fromphone: '',
                    fortype: '',
                },
                ruleValidate: {},
                fortypeArr: [],
            }
        },
        mounted: function () {
            let id = this.$route.query.id;


            if (id && id.length > 0) {

                this.getDetail(id)
            }

        },

        methods: {
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                })
            },
            getForTypeData: function () {
                let that = this;

                let params = '';
                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.MaterialTypeList, params, function (res) {
                    that.$Loading.finish();

                    that.fortypeArr = res.Msg;
                });
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    curPage: this.$route.query.curPage,
                    pageSize: 10,
                };

                apiUtil.get(that, apiUtil.urls.MaterialList, para, function (res) {
                    that.$Loading.finish();
                    let data = res.Msg.Arrays[that.$route.query.index];

                    that.formValidate.title = data.Title;
                    that.formValidate.serial = data.Serial;
                    that.formValidate.size = data.Size;
                    that.formValidate.fortype = data.Fortype;
                    that.formValidate.fromphone = data.Fromphone;
                    that.formValidate.fromcontact = data.Fromcontact;
                    that.formValidate.byfrom = data.Byfrom;
                    that.formValidate.vender = data.Vender;
                    that.getForTypeData();

                });
            },
            //修改
            updateData: function (model) {
                let that = this;

                model.id =this.$route.query.id;
                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.EditMaterialItem, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('编辑成功')
                });
            },


        }
    }
</script>
